#include "Comm.hpp"
#include "Fifo.hpp"

int main()
{
    //获取共享内存
    int key=GetShmKey();
    std::cout << "key: "<< ToHex(key) << std::endl;
    
    //创建共享内存
    int shmid = CreateShm(key,defaultsize);
    std:: cout<< "shmid: "<< shmid << std::endl;

    //将共享内存和进程进行挂接(关联)
    char *addr =(char*)ShmAttach(shmid);
    std::cout<<"Attact success"<<std::endl;
    //引入管道 

    Fifo fifo;
    Sync syn;
    syn.OpenReadOrdie();

    for(;;)
    {
        syn.Wait();
        cout << "shm content: "<< addr << std::endl;
        sleep(1);
    }
     //去关联
     ShmDetach(addr);
    //删除共享内存
    DeleteShm(shmid);
    
    return 0;
}
